package com.yonyou.crm.sys.menu.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.crm.common.model.util.ModelUtil;
import com.yonyou.crm.sys.menu.entity.MenuModuleDO;
import com.yonyou.crm.sys.menu.entity.MenuModuleVO;
import com.yonyou.crm.sys.menu.entity.MenuGroupVO;
@Service
public class MenuModuleBizServiceImpl extends BaseBizServiceImpl<MenuModuleDO>{

	@Autowired
	private MenuGroupServiceImpl menuGroupService;
	
	public List<MenuModuleVO> getModuleList() {
		
		List<MenuModuleDO> modules =dao.selectVoList(MenuModuleDO.class, "getModuleList",null);
		if(modules!=null&&modules.size()>0){
			List<MenuModuleVO> modulevos = new ArrayList<MenuModuleVO>(modules.size()); 
			for(MenuModuleDO moduleDo : modules){
				MenuModuleVO vo = ModelUtil.copyModel(moduleDo, MenuModuleVO.class);
				List<MenuGroupVO> menuGroups = menuGroupService.getPcMenuGroup(vo.getId());
				if(menuGroups!=null && menuGroups.size() > 0){
					vo.setChild(menuGroups.toArray(new MenuGroupVO[menuGroups.size()]));
					modulevos.add(vo);
				}
			}
			return modulevos;
		}
		return null;
	}
	
	
}
